/*
 * Copyright @2007-2008 by Infowarelab Webapps.
 */
package com.easyidea.its.domain.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;


@MappedSuperclass
public class BaseEntity implements IBean, Serializable {

	private static final long serialVersionUID = -3142581786384727794L;

	/**
	 * identify -- auto_increment
	 */
	protected Integer id = new Integer("-1");

	private Date createTime = new Date();

	private Date modifyTime = new Date();

	private String creator;

	private String modifier;

	/**
	 * is logic delete or not. true -- logic delete
	 */
	private boolean isDeleted = false;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "create_date")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "modified_date")
	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}

	@Column(name = "creator")
	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	@Column(name = "modifior")
	public String getModifier() {
		return modifier;
	}

	public void setModifier(String modifier) {
		this.modifier = modifier;
	}

	@Column(name = "is_deleted", nullable = false)
	public boolean isDeleted() {
		return isDeleted;
	}

	public void setDeleted(boolean isDeleted) {
		this.isDeleted = isDeleted;
	}
	
	@Override
	public String toString(){
		return getClass().getName()+"#"+getId();
	}

	@Override
	public boolean equals(final Object entity){
		return entity!=null&&entity.getClass().equals(getClass())&&
		((IBean)entity).getId().equals(getId());
	}
	
	@Override
	public int hashCode() {
		return toString().hashCode();
	}

}
